﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
using Newtonsoft.Json;

public class Global  : SingletonMono<Global>{
    [SerializeField]
    ActorData actorInfo;
    public ActorData Actor { get { return actorInfo; } }
    public void LoadUserData()
    {
        actorInfo = ResMgr.Instantce.LoadJsonData<ActorData>();
        //var actor_string = PlayerPrefs.GetString("Actor");
        //actorInfo = JsonConvert.DeserializeObject<ActorData>(actor_string);
        if(actorInfo == null)
        {
            NewUser();
        }
    }

    public void SaveUserData()
    {
        //PlayerPrefs.SetString("Actor", actorInfo.ToString());
        ResMgr.Instantce.SaveJsonData<ActorData>(actorInfo);
    }

    public void NewUser()
    {
        actorInfo = new ActorData();
        actorInfo.actorGUID = Guid.NewGuid().ToString();
        actorInfo.name = "尊贵大侠";
        actorInfo.regTime = DateTime.Now.Ticks;
        Log.InfoFormat("CreatNew User " + Actor.ToString());
    }
    public void NewGUID()
    {
        actorInfo.actorGUID = Guid.NewGuid().ToString();
    }

}
